package com.bw.services.visit.model

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import androidx.lifecycle.viewModelScope
import com.bw.lib_base.base.BaseViewModel
import com.bw.services.visit.entity.VisitData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class VisitViewModel @Inject constructor(
     val  visitRepo: VisitRepo
) :BaseViewModel(){
    private val _visitData = MutableStateFlow<List<VisitData>?>(null)
    val visitData:StateFlow<List<VisitData>?> = _visitData

    fun getVisitData(){
        viewModelScope.launch {
            if (isInitLife()){
                lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED){
                   val visitDataList = visitRepo.getVisit()
                    _visitData.emit(visitDataList)

                }
            }
        }
    }

}